Tuikit
Tuikit is a TUI library for writing terminal UI applications. Highlights:
- Thread safe.
- Support non-fullscreen mode as well as fullscreen mode.
- Support
Alt
keys, mouse events, etc. - Buffering for efficient rendering.
Tuikit is modeld after termbox which views the terminal as a table of fixed-size cells and input being a stream of structured messages.
WARNING: The library is not stable yet, the API might change.
Usage
In your Cargo.toml
add the following:
[]
= "*"
And if you'd like to use the latest snapshot version:
[]
= { = "https://github.com/lotabout/tuikit.git" }
Here is an example (could also be run by cargo run --example hello-world
):
use *;
use ;
Layout
tuikit
provides HSplit
, VSplit
and Win
for managing layouts:
HSplit
allow you to split area horizontally into pieces.VSplit
works just likeHSplit
but splits vertically.Win
do not split, it could have margin, padding and border.
For example:
use *;
;
The split algorithm is simple:
- Both
HSplit
andVSplit
will take severalSplit
where aSplit
would contains:- basis, the original size
- grow, the factor to grow if there is still enough room
- shrink, the factor to shrink if there is not enough room
HSplit/VSplit
will count the total width/height(basis) of the split items- Judge if the current width/height is enough or not for the split items
- shrink/grow the split items according to their grow/shrink:
factor / sum(factors)
- If still not enough room, the last one(s) would be set width/height 0
References
Tuikit
borrows ideas from lots of other projects:
- rustyline Readline Implementation in Rust.
- How to enter the raw mode.
- Part of the keycode parsing logic.
- termion A bindless library for controlling terminals/TTY.
- How to parse mouse events.
- How to enter raw mode.
- rustbox and termbox
- The idea of viewing terminal as table of fixed cells.
- termfest Easy TUI library written in Rust
- The buffering idea.